home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / src / binutils.252 / gas / write.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-18  |  65.6 KB  |  2,429 lines

  1. /* write.c - emit .o file
  2.    Copyright (C) 1986, 87, 90, 91, 92, 93, 1994 Free Software Foundation, Inc.
  3.  
  4.    This file is part of GAS, the GNU Assembler.
  5.  
  6.    GAS is free software; you can redistribute it and/or modify
  7.    it under the terms of the GNU General Public License as published by
  8.    the Free Software Foundation; either version 2, or (at your option)
  9.    any later version.
  10.  
  11.    GAS is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with GAS; see the file COPYING.  If not, write to
  18.    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /* This thing should be set up to do byteordering correctly.  But... */
  21.  
  22. #include "as.h"
  23. #include "subsegs.h"
  24. #include "obstack.h"
  25. #include "output-file.h"
  26.  
  27. /* This looks like a good idea.  Let's try turning it on always, for now.  */
  28. #undef  BFD_FAST_SECTION_FILL
  29. #define BFD_FAST_SECTION_FILL
  30.  
  31. /* The NOP_OPCODE is for the alignment fill value.  Fill it with a nop
  32.    instruction so that the disassembler does not choke on it.  */
  33. #ifndef NOP_OPCODE
  34. #define NOP_OPCODE 0x00
  35. #endif
  36.  
  37. #ifndef TC_ADJUST_RELOC_COUNT
  38. #define TC_ADJUST_RELOC_COUNT(FIXP,COUNT)
  39. #endif
  40.  
  41. #ifndef TC_FORCE_RELOCATION
  42. #define TC_FORCE_RELOCATION(FIXP) 0
  43. #endif
  44.  
  45. #ifndef WORKING_DOT_WORD
  46. extern CONST int md_short_jump_size;
  47. extern CONST int md_long_jump_size;
  48. #endif
  49.  
  50. int symbol_table_frozen;
  51. void print_fixup PARAMS ((fixS *));
  52.  
  53. #ifdef BFD_ASSEMBLER
  54. /* We generally attach relocs to frag chains.  However, after we have
  55.    chained these all together into a segment, any relocs we add after
  56.    that must be attached to a segment.  This will include relocs added
  57.    in md_estimate_size_for_relax, for example.  */
  58. static int frags_chained = 0;
  59. #endif
  60.  
  61. #ifndef BFD_ASSEMBLER
  62.  
  63. #ifndef MANY_SEGMENTS
  64. struct frag *text_frag_root;
  65. struct frag *data_frag_root;
  66. struct frag *bss_frag_root;
  67.  
  68. struct frag *text_last_frag;    /* Last frag in segment. */
  69. struct frag *data_last_frag;    /* Last frag in segment. */
  70. static struct frag *bss_last_frag;    /* Last frag in segment. */
  71. #endif
  72.  
  73. #ifndef BFD
  74. static object_headers headers;
  75. static char *the_object_file;
  76. #endif
  77.  
  78. long string_byte_count;
  79. char *next_object_file_charP;    /* Tracks object file bytes. */
  80.  
  81. #ifndef OBJ_VMS
  82. int magic_number_for_object_file = DEFAULT_MAGIC_NUMBER_FOR_OBJECT_FILE;
  83. #endif
  84.  
  85. #endif /* BFD_ASSEMBLER */
  86.  
  87. #ifdef BFD_ASSEMBLER
  88. static fixS *fix_new_internal PARAMS ((fragS *, int where, int size,
  89.                        symbolS *add, symbolS *sub,
  90.                        offsetT offset, int pcrel,
  91.                        bfd_reloc_code_real_type r_type));
  92. #else
  93. static fixS *fix_new_internal PARAMS ((fragS *, int where, int size,
  94.                        symbolS *add, symbolS *sub,
  95.                        offsetT offset, int pcrel,
  96.                        int r_type));
  97. #endif
  98. #if defined (BFD_ASSEMBLER) || !defined (BFD)
  99. static long fixup_segment PARAMS ((fixS * fixP, segT this_segment_type));
  100. #endif
  101. static relax_addressT relax_align PARAMS ((relax_addressT addr, int align));
  102.  
  103. /*
  104.  *            fix_new()
  105.  *
  106.  * Create a fixS in obstack 'notes'.
  107.  */
  108. static fixS *
  109. fix_new_internal (frag, where, size, add_symbol, sub_symbol, offset, pcrel,
  110.           r_type)
  111.      fragS *frag;        /* Which frag? */
  112.      int where;            /* Where in that frag? */
  113.      int size;            /* 1, 2, or 4 usually. */
  114.      symbolS *add_symbol;    /* X_add_symbol. */
  115.      symbolS *sub_symbol;    /* X_op_symbol. */
  116.      offsetT offset;        /* X_add_number. */
  117.      int pcrel;            /* TRUE if PC-relative relocation. */
  118. #ifdef BFD_ASSEMBLER
  119.      bfd_reloc_code_real_type r_type; /* Relocation type */
  120. #else
  121.      int r_type;        /* Relocation type */
  122. #endif
  123. {
  124.   fixS *fixP;
  125.  
  126.   fixP = (fixS *) obstack_alloc (¬es, sizeof (fixS));
  127.  
  128.   fixP->fx_frag = frag;
  129.   fixP->fx_where = where;
  130.   fixP->fx_size = size;
  131.   fixP->fx_addsy = add_symbol;
  132.   fixP->fx_subsy = sub_symbol;
  133.   fixP->fx_offset = offset;
  134.   fixP->fx_pcrel = pcrel;
  135.   fixP->fx_plt = 0;
  136. #if defined(NEED_FX_R_TYPE) || defined (BFD_ASSEMBLER)
  137.   fixP->fx_r_type = r_type;
  138. #endif
  139.   fixP->fx_im_disp = 0;
  140.   fixP->fx_pcrel_adjust = 0;
  141.   fixP->fx_bit_fixP = 0;
  142.   fixP->fx_addnumber = 0;
  143.   fixP->tc_fix_data = NULL;
  144.   fixP->fx_tcbit = 0;
  145.   fixP->fx_done = 0;
  146.  
  147. #ifdef TC_something
  148.   fixP->fx_bsr = 0;
  149. #endif
  150.  
  151.   as_where (&fixP->fx_file, &fixP->fx_line);
  152.  
  153.   /* Usually, we want relocs sorted numerically, but while
  154.      comparing to older versions of gas that have relocs
  155.      reverse sorted, it is convenient to have this compile
  156.      time option.  xoxorich. */
  157.  
  158.   {
  159.  
  160. #ifdef BFD_ASSEMBLER
  161.     fixS **seg_fix_rootP = (frags_chained
  162.                 ? &seg_info (now_seg)->fix_root
  163.                 : &frchain_now->fix_root);
  164.     fixS **seg_fix_tailP = (frags_chained
  165.                 ? &seg_info (now_seg)->fix_tail
  166.                 : &frchain_now->fix_tail);
  167. #endif
  168.  
  169. #ifdef REVERSE_SORT_RELOCS
  170.  
  171.     fixP->fx_next = *seg_fix_rootP;
  172.     *seg_fix_rootP = fixP;
  173.  
  174. #else /* REVERSE_SORT_RELOCS */
  175.  
  176.     fixP->fx_next = NULL;
  177.  
  178.     if (*seg_fix_tailP)
  179.       (*seg_fix_tailP)->fx_next = fixP;
  180.     else
  181.       *seg_fix_rootP = fixP;
  182.     *seg_fix_tailP = fixP;
  183.  
  184. #endif /* REVERSE_SORT_RELOCS */
  185.  
  186.   }
  187.  
  188.   return fixP;
  189. }
  190.  
  191. /* Create a fixup relative to a symbol (plus a constant).  */
  192.  
  193. fixS *
  194. fix_new (frag, where, size, add_symbol, offset, pcrel, r_type)
  195.      fragS *frag;        /* Which frag? */
  196.      int where;            /* Where in that frag? */
  197.      short int size;        /* 1, 2, or 4 usually. */
  198.      symbolS *add_symbol;    /* X_add_symbol. */
  199.      offsetT offset;        /* X_add_number. */
  200.      int pcrel;            /* TRUE if PC-relative relocation. */
  201. #ifdef BFD_ASSEMBLER
  202.      bfd_reloc_code_real_type r_type; /* Relocation type */
  203. #else
  204.      int r_type;        /* Relocation type */
  205. #endif
  206. {
  207.   return fix_new_internal (frag, where, size, add_symbol,
  208.                (symbolS *) NULL, offset, pcrel, r_type);
  209. }
  210.  
  211. /* Create a fixup for an expression.  Currently we only support fixups
  212.    for difference expressions.  That is itself more than most object
  213.    file formats support anyhow.  */
  214.  
  215. fixS *
  216. fix_new_exp (frag, where, size, exp, pcrel, r_type)
  217.      fragS *frag;        /* Which frag? */
  218.      int where;            /* Where in that frag? */
  219.      short int size;        /* 1, 2, or 4 usually. */
  220.      expressionS *exp;        /* Expression.  */
  221.      int pcrel;            /* TRUE if PC-relative relocation. */
  222. #ifdef BFD_ASSEMBLER
  223.      bfd_reloc_code_real_type r_type; /* Relocation type */
  224. #else
  225.      int r_type;        /* Relocation type */
  226. #endif
  227. {
  228.   symbolS *add = NULL;
  229.   symbolS *sub = NULL;
  230.   offsetT off = 0;
  231.   
  232.   switch (exp->X_op)
  233.     {
  234.     case O_absent:
  235.       break;
  236.  
  237. /*    case O_constant:
  238.       /* Generate a symbol for now.  This actually helps avoid having a
  239.      local "section symbol" for the absolute section emitted with many
  240.      files.  Perhaps a better place to fix this would be in
  241.      adjust_reloc_syms, where that silly symbol is explicitly fetched,
  242.      but in some instances, for some targets, *some* symbol is
  243.      required, so I'm not sure if I can eliminate that code.  */
  244.  
  245.     case O_add:
  246.       /* This comes up when _GLOBAL_OFFSET_TABLE_+(.-L0) is read, if
  247.      the difference expression cannot immediately be reduced.  */
  248.       {
  249.     extern symbolS *make_expr_symbol ();
  250.     symbolS *stmp = make_expr_symbol (exp);
  251.     exp->X_op = O_symbol;
  252.     exp->X_op_symbol = 0;
  253.     exp->X_add_symbol = stmp;
  254.     exp->X_add_number = 0;
  255.     return fix_new_exp (frag, where, size, exp, pcrel, r_type);
  256.       }
  257.  
  258.     case O_uminus:
  259.       sub = exp->X_add_symbol;
  260.       off = exp->X_add_number;
  261.       break;
  262.  
  263.     case O_subtract:
  264.       sub = exp->X_op_symbol;
  265.       /* Fall through.  */
  266.     case O_symbol:
  267.       add = exp->X_add_symbol;
  268.       /* Fall through.   */
  269.     case O_constant:
  270.       off = exp->X_add_number;
  271.       break;
  272.  
  273.     default:
  274.       as_bad ("expression too complex for fixup");
  275.     }
  276.  
  277.   return fix_new_internal (frag, where, size, add, sub, off,
  278.                pcrel, r_type);
  279. }
  280.  
  281. /* Append a string onto another string, bumping the pointer along.  */
  282. void
  283. append (charPP, fromP, length)
  284.      char **charPP;
  285.      char *fromP;
  286.      unsigned long length;
  287. {
  288.   /* Don't trust memcpy() of 0 chars. */
  289.   if (length == 0)
  290.     return;
  291.  
  292.   memcpy (*charPP, fromP, length);
  293.   *charPP += length;
  294. }
  295.  
  296. #ifndef BFD_ASSEMBLER 
  297. int section_alignment[SEG_MAXIMUM_ORDINAL];
  298. #endif
  299.  
  300. /*
  301.  * This routine records the largest alignment seen for each segment.
  302.  * If the beginning of the segment is aligned on the worst-case
  303.  * boundary, all of the other alignments within it will work.  At
  304.  * least one object format really uses this info.
  305.  */
  306. void 
  307. record_alignment (seg, align)
  308.      /* Segment to which alignment pertains */
  309.      segT seg;
  310.      /* Alignment, as a power of 2 (e.g., 1 => 2-byte boundary, 2 => 4-byte
  311.     boundary, etc.)  */
  312.      int align;
  313. {
  314. #ifdef BFD_ASSEMBLER
  315.   if (align > bfd_get_section_alignment (stdoutput, seg))
  316.     bfd_set_section_alignment (stdoutput, seg, align);
  317. #else
  318.   if (align > section_alignment[(int) seg])
  319.     section_alignment[(int) seg] = align;
  320. #endif
  321. }
  322.  
  323. #if defined (BFD_ASSEMBLER) || ! defined (BFD)
  324.  
  325. static fragS *
  326. chain_frchains_together_1 (section, frchp)
  327.      segT section;
  328.      struct frchain *frchp;
  329. {
  330.   fragS dummy, *prev_frag = &dummy;
  331.   fixS fix_dummy, *prev_fix = &fix_dummy;
  332.  
  333.   for (; frchp && frchp->frch_seg == section; frchp = frchp->frch_next)
  334.     {
  335.       prev_frag->fr_next = frchp->frch_root;
  336.       prev_frag = frchp->frch_last;
  337. #ifdef BFD_ASSEMBLER
  338.       if (frchp->fix_root != (fixS *) NULL)
  339.     {
  340.       if (seg_info (section)->fix_root == (fixS *) NULL)
  341.         seg_info (section)->fix_root = frchp->fix_root;
  342.       prev_fix->fx_next = frchp->fix_root;
  343.       seg_info (section)->fix_tail = frchp->fix_tail;
  344.       prev_fix = frchp->fix_tail;
  345.     }
  346. #endif
  347.     }
  348.   prev_frag->fr_next = 0;
  349.   return prev_frag;
  350. }
  351.  
  352. #endif
  353.  
  354. #ifdef BFD_ASSEMBLER
  355.  
  356. static void
  357. chain_frchains_together (abfd, section, xxx)
  358.      bfd *abfd;            /* unused */
  359.      segT section;
  360.      PTR xxx;            /* unused */
  361. {
  362.   segment_info_type *info;
  363.  
  364.   /* BFD may have introduced its own sections without using
  365.      subseg_new, so it is possible that seg_info is NULL.  */
  366.   info = seg_info (section);
  367.   if (info != (segment_info_type *) NULL)
  368.    info->frchainP->frch_last
  369.      = chain_frchains_together_1 (section, info->frchainP);
  370.  
  371.   /* Now that we've chained the frags together, we must add new fixups
  372.      to the segment, not to the frag chain.  */
  373.   frags_chained = 1;
  374. }
  375.  
  376. #endif
  377.  
  378. #if !defined (BFD) && !defined (BFD_ASSEMBLER)
  379.  
  380. void 
  381. remove_subsegs (head, seg, root, last)
  382.      frchainS *head;
  383.      int seg;
  384.      fragS **root;
  385.      fragS **last;
  386. {
  387.   *root = head->frch_root;
  388.   *last = chain_frchains_together_1 (seg, head);
  389. }
  390.  
  391. #endif /* BFD */
  392.  
  393. #if defined (BFD_ASSEMBLER) || !defined (BFD)
  394.  
  395. #ifdef BFD_ASSEMBLER
  396. static void
  397. cvt_frag_to_fill (sec, fragP)
  398.      segT sec;
  399.      fragS *fragP;
  400. #else
  401. static void
  402. cvt_frag_to_fill (headers, fragP)
  403.      object_headers *headers;
  404.      fragS *fragP;
  405. #endif
  406. {
  407.   switch (fragP->fr_type)
  408.     {
  409.     case rs_align:
  410.     case rs_org:
  411. #ifdef HANDLE_ALIGN
  412.       HANDLE_ALIGN (fragP);
  413. #endif
  414.       fragP->fr_type = rs_fill;
  415.       know (fragP->fr_next != NULL);
  416.       fragP->fr_offset = (fragP->fr_next->fr_address
  417.               - fragP->fr_address
  418.               - fragP->fr_fix) / fragP->fr_var;
  419.       break;
  420.  
  421.     case rs_fill:
  422.       break;
  423.  
  424.     case rs_machine_dependent:
  425. #ifdef BFD_ASSEMBLER
  426.       md_convert_frag (stdoutput, sec, fragP);
  427. #else
  428.       md_convert_frag (headers, fragP);
  429. #endif
  430.  
  431.       assert (fragP->fr_next == NULL || (fragP->fr_next->fr_address - fragP->fr_address == fragP->fr_fix));
  432.  
  433.       /*
  434.        * After md_convert_frag, we make the frag into a ".space 0".
  435.        * Md_convert_frag() should set up any fixSs and constants
  436.        * required.
  437.        */
  438.       frag_wane (fragP);
  439.       break;
  440.  
  441. #ifndef WORKING_DOT_WORD
  442.     case rs_broken_word:
  443.       {
  444.     struct broken_word *lie;
  445.  
  446.     if (fragP->fr_subtype)
  447.       {
  448.         fragP->fr_fix += md_short_jump_size;
  449.         for (lie = (struct broken_word *) (fragP->fr_symbol);
  450.          lie && lie->dispfrag == fragP;
  451.          lie = lie->next_broken_word)
  452.           if (lie->added == 1)
  453.         fragP->fr_fix += md_long_jump_size;
  454.       }
  455.     frag_wane (fragP);
  456.       }
  457.       break;
  458. #endif
  459.  
  460.     default:
  461.       BAD_CASE (fragP->fr_type);
  462.       break;
  463.     }
  464. }
  465.  
  466. #endif /* defined (BFD_ASSEMBLER) || !defined (BFD) */
  467.  
  468. #ifdef BFD_ASSEMBLER
  469. static void
  470. relax_and_size_seg (abfd, sec, xxx)
  471.      bfd *abfd;
  472.      asection *sec;
  473.      PTR xxx;
  474. {
  475.   flagword flags;
  476.   fragS *fragp;
  477.   segment_info_type *seginfo;
  478.   int x;
  479.   valueT size, newsize;
  480.  
  481.   flags = bfd_get_section_flags (abfd, sec);
  482.  
  483.   seginfo = seg_info (sec);
  484.   if (seginfo && seginfo->frchainP)
  485.     {
  486.       relax_segment (seginfo->frchainP->frch_root, sec);
  487.       for (fragp = seginfo->frchainP->frch_root; fragp; fragp = fragp->fr_next)
  488.     cvt_frag_to_fill (sec, fragp);
  489.       for (fragp = seginfo->frchainP->frch_root;
  490.        fragp->fr_next;
  491.        fragp = fragp->fr_next)
  492.     /* walk to last elt */;
  493.       size = fragp->fr_address + fragp->fr_fix;
  494.     }
  495.   else
  496.     size = 0;
  497.  
  498.   if (size > 0 && ! seginfo->bss)
  499.     flags |= SEC_HAS_CONTENTS;
  500.  
  501.   /* @@ This is just an approximation.  */
  502.   if (seginfo && seginfo->fix_root)
  503.     flags |= SEC_RELOC;
  504.   else
  505.     flags &= ~SEC_RELOC;
  506.   x = bfd_set_section_flags (abfd, sec, flags);
  507.   assert (x == true);
  508.  
  509.   newsize = md_section_align (sec, size);
  510.   x = bfd_set_section_size (abfd, sec, newsize);
  511.   assert (x == true);
  512.  
  513.   /* If the size had to be rounded up, add some padding in the last
  514.      non-empty frag.  */
  515.   assert (newsize >= size);
  516.   if (size != newsize)
  517.     {
  518.       fragS *last = seginfo->frchainP->frch_last;
  519.       fragp = seginfo->frchainP->frch_root;
  520.       while (fragp->fr_next != last)
  521.     fragp = fragp->fr_next;
  522.       last->fr_address = size;
  523.       fragp->fr_offset += newsize - size;
  524.     }
  525.  
  526. #ifdef tc_frob_section
  527.   tc_frob_section (sec);
  528. #endif
  529. #ifdef obj_frob_section
  530.   obj_frob_section (sec);
  531. #endif
  532. }
  533.  
  534. #ifdef DEBUG2
  535. static void
  536. dump_section_relocs (abfd, sec, stream_)
  537.      bfd *abfd;
  538.      asection *sec;
  539.      char *stream_;
  540. {
  541.   FILE *stream = (FILE *) stream_;
  542.   segment_info_type *seginfo = seg_info (sec);
  543.   fixS *fixp = seginfo->fix_root;
  544.  
  545.   if (!fixp)
  546.     return;
  547.  
  548.   fprintf (stream, "sec %s relocs:\n", sec->name);
  549.   while (fixp)
  550.     {
  551.       symbolS *s = fixp->fx_addsy;
  552.       if (s)
  553.     {
  554.       fprintf (stream, "  %08x: %s(%s", fixp, S_GET_NAME (s),
  555.            s->bsym->section->name);
  556.       if (s->bsym->flags & BSF_SECTION_SYM)
  557.         {
  558.           fprintf (stream, " section sym");
  559.           if (S_GET_VALUE (s))
  560.         fprintf (stream, "+%x", S_GET_VALUE (s));
  561.         }
  562.       else
  563.         fprintf (stream, "+%x", S_GET_VALUE (s));
  564.       fprintf (stream, ")+%x\n", fixp->fx_offset);
  565.     }
  566.       else
  567.     fprintf (stream, "  %08x: type %d no sym\n", fixp, fixp->fx_r_type);
  568.       fixp = fixp->fx_next;
  569.     }
  570. }
  571. #else
  572. #define dump_section_relocs(ABFD,SEC,STREAM)    (void)(ABFD,SEC,STREAM)
  573. #endif
  574.  
  575. #ifndef EMIT_SECTION_SYMBOLS
  576. #define EMIT_SECTION_SYMBOLS 1
  577. #endif
  578.  
  579. static void
  580. adjust_reloc_syms (abfd, sec, xxx)
  581.      bfd *abfd;
  582.      asection *sec;
  583.      PTR xxx;
  584. {
  585.   segment_info_type *seginfo = seg_info (sec);
  586.   fixS *fixp;
  587.  
  588.   if (seginfo == NULL)
  589.     return;
  590.  
  591.   dump_section_relocs (abfd, sec, stderr);
  592.  
  593.   for (fixp = seginfo->fix_root; fixp; fixp = fixp->fx_next)
  594.     if (fixp->fx_done)
  595.       /* ignore it */;
  596.     else if (fixp->fx_addsy)
  597.       {
  598.     symbolS *sym;
  599.     asection *symsec;
  600.  
  601.       reduce_fixup:
  602.  
  603. #ifdef DEBUG5
  604.     fprintf (stderr, "\n\nadjusting fixup:\n");
  605.     print_fixup (fixp);
  606. #endif
  607.  
  608.     sym = fixp->fx_addsy;
  609.     symsec = sym->bsym->section;
  610.  
  611.     /* If it's one of these sections, assume the symbol is
  612.        definitely going to be output.  The code in
  613.        md_estimate_size_before_relax in tc-mips.c uses this test
  614.        as well, so if you change this code you should look at that
  615.        code.  */
  616.     if (symsec == &bfd_und_section
  617.         || symsec == &bfd_abs_section
  618.         || bfd_is_com_section (symsec))
  619.       {
  620.         fixp->fx_addsy->sy_used_in_reloc = 1;
  621.         goto done;
  622.       }
  623.  
  624.     /* Since we're reducing to section symbols, don't attempt to reduce
  625.        anything that's already using one.  */
  626.     if (sym->bsym->flags & BSF_SECTION_SYM)
  627.       {
  628.         fixp->fx_addsy->sy_used_in_reloc = 1;
  629.         goto done;
  630.       }
  631.  
  632.     /* Is there some other reason we can't adjust this one?  (E.g.,
  633.        call/bal links in i960-bout symbols.)  */
  634. #ifdef obj_fix_adjustable
  635.     if (! obj_fix_adjustable (fixp))
  636.       {
  637.         fixp->fx_addsy->sy_used_in_reloc = 1;
  638.         goto done;
  639.       }
  640. #endif
  641.  
  642.     /* Is there some other (target cpu dependent) reason we can't adjust
  643.        this one?  (E.g. relocations involving function addresses on 
  644.        the PA.  */
  645. #ifdef tc_fix_adjustable
  646.     if (! tc_fix_adjustable (fixp))
  647.       {
  648.         fixp->fx_addsy->sy_used_in_reloc = 1;
  649.         goto done;
  650.       }
  651. #endif
  652.  
  653.     /* For PIC support: We may get expressions like
  654.        "_GLOBAL_OFFSET_TABLE_+(.-L5)" where "." and "L5" may not
  655.        necessarily have had a fixed difference initially.  But now
  656.        it should be a known constant, so we can reduce it.  Since
  657.        we can't easily handle a symbol value that looks like
  658.        someUndefinedSymbol+const, though, we convert the fixup to
  659.        access the undefined symbol directly, and discard the
  660.        intermediate symbol.  */
  661.     if (S_GET_SEGMENT (sym) == expr_section
  662.         && sym->sy_value.X_op == O_add
  663.         && (resolve_symbol_value (sym->sy_value.X_add_symbol),
  664.         S_GET_SEGMENT (sym->sy_value.X_add_symbol) == undefined_section)
  665.         && (resolve_symbol_value (sym->sy_value.X_op_symbol),
  666.         S_GET_SEGMENT (sym->sy_value.X_op_symbol) == absolute_section))
  667.       {
  668.         fixp->fx_offset += S_GET_VALUE (sym->sy_value.X_op_symbol);
  669.         fixp->fx_offset += sym->sy_value.X_add_number;
  670.         fixp->fx_addsy = sym->sy_value.X_add_symbol;
  671.         goto reduce_fixup;
  672.       }
  673.  
  674.     /* If the section symbol isn't going to be output, the relocs
  675.        at least should still work.  If not, figure out what to do
  676.        when we run into that case.  */
  677.     fixp->fx_offset += S_GET_VALUE (sym);
  678.     fixp->fx_addsy = section_symbol (symsec);
  679.     fixp->fx_addsy->sy_used_in_reloc = 1;
  680.  
  681.       done:
  682.     ;
  683.       }
  684. #if 1/*def RELOC_REQUIRES_SYMBOL*/
  685.     else
  686.       {
  687.     /* There was no symbol required by this relocation.  However,
  688.        BFD doesn't really handle relocations without symbols well.
  689.        (At least, the COFF support doesn't.)  So for now we fake up
  690.        a local symbol in the absolute section.  */
  691.  
  692.     fixp->fx_addsy = section_symbol (absolute_section);
  693. /*    fixp->fx_addsy->sy_used_in_reloc = 1; */
  694.       }
  695. #endif
  696.  
  697.   dump_section_relocs (abfd, sec, stderr);
  698. }
  699.  
  700. static void
  701. write_relocs (abfd, sec, xxx)
  702.      bfd *abfd;
  703.      asection *sec;
  704.      PTR xxx;
  705. {
  706.   segment_info_type *seginfo = seg_info (sec);
  707.   int i;
  708.   unsigned int n;
  709.   arelent **relocs;
  710.   fixS *fixp;
  711.   char *err;
  712.  
  713.   /* If seginfo is NULL, we did not create this section; don't do
  714.      anything with it.  */
  715.   if (seginfo == NULL)
  716.     return;
  717.  
  718.   fixup_segment (seginfo->fix_root, sec);
  719.  
  720.   n = 0;
  721.   for (fixp = seginfo->fix_root; fixp; fixp = fixp->fx_next)
  722.     n++;
  723.  
  724. #ifndef RELOC_EXPANSION_POSSIBLE
  725.   /* Set up reloc information as well.  */
  726.   relocs = (arelent **) bfd_alloc_by_size_t (stdoutput,
  727.                          n * sizeof (arelent *));
  728.   memset ((char*)relocs, 0, n * sizeof (arelent*));
  729.  
  730.   i = 0;
  731.   for (fixp = seginfo->fix_root; fixp != (fixS *) NULL; fixp = fixp->fx_next)
  732.     {
  733.       arelent *reloc;
  734.       bfd_reloc_status_type s;
  735.  
  736.       if (fixp->fx_done)
  737.     {
  738.       n--;
  739.       continue;
  740.     }
  741.       reloc = tc_gen_reloc (sec, fixp);
  742.       if (!reloc)
  743.     {
  744.       n--;
  745.       continue;
  746.     }
  747.       if (fixp->fx_where + fixp->fx_size
  748.       > fixp->fx_frag->fr_fix + fixp->fx_frag->fr_offset)
  749.     abort ();
  750.  
  751.       s = bfd_install_relocation (stdoutput, reloc,
  752.                   fixp->fx_frag->fr_literal,
  753.                   fixp->fx_frag->fr_address,
  754.                   sec, &err);
  755.       switch (s)
  756.     {
  757.     case bfd_reloc_ok:
  758.       break;
  759.     case bfd_reloc_overflow:
  760.       as_bad_where (fixp->fx_file, fixp->fx_line, "relocation overflow");
  761.       break;
  762.     default:
  763.       as_fatal ("%s:%u: bad return from bfd_perform_relocation",
  764.             fixp->fx_file, fixp->fx_line);
  765.     }
  766.       relocs[i++] = reloc;
  767.     }
  768. #else
  769.   n = n * MAX_RELOC_EXPANSION;
  770.   /* Set up reloc information as well.  */
  771.   relocs = (arelent **) bfd_alloc_by_size_t (stdoutput,
  772.                          n * sizeof (arelent *));
  773.  
  774.   i = 0;
  775.   for (fixp = seginfo->fix_root; fixp != (fixS *) NULL; fixp = fixp->fx_next)
  776.     {
  777.       arelent **reloc;
  778.       char *data;
  779.       bfd_reloc_status_type s;
  780.       int j;
  781.  
  782.       if (fixp->fx_done)
  783.     {
  784.       n--;
  785.       continue;
  786.     }
  787.       reloc = tc_gen_reloc (sec, fixp);
  788.  
  789.       for (j = 0; reloc[j]; j++)
  790.     {
  791.           relocs[i++] = reloc[j];
  792.           assert(i <= n);
  793.     }
  794.       data = fixp->fx_frag->fr_literal + fixp->fx_where;
  795.       if (fixp->fx_where + fixp->fx_size
  796.       > fixp->fx_frag->fr_fix + fixp->fx_frag->fr_offset)
  797.     abort ();
  798.       for (j = 0; reloc[j]; j++)
  799.         {
  800.       s = bfd_perform_relocation (stdoutput, reloc[j],
  801.                       data - reloc[0]->address,
  802.                       sec, stdoutput, &err);
  803.           switch (s)
  804.         {
  805.         case bfd_reloc_ok:
  806.           break;
  807.         case bfd_reloc_overflow:
  808.           as_bad_where (fixp->fx_file, fixp->fx_line,
  809.                 "relocation overflow");
  810.           break;
  811.         default:
  812.           as_fatal ("%s:%u: bad return from bfd_perform_relocation",
  813.             fixp->fx_file, fixp->fx_line);
  814.         }
  815.         }
  816.     }
  817.   n = i;
  818. #endif
  819.  
  820. #ifdef DEBUG4
  821.   {
  822.     int i, j, nsyms;
  823.     asymbol **sympp;
  824.     sympp = bfd_get_outsymbols (stdoutput);
  825.     nsyms = bfd_get_symcount (stdoutput);
  826.     for (i = 0; i < n; i++)
  827.       if (((*relocs[i]->sym_ptr_ptr)->flags & BSF_SECTION_SYM) == 0)
  828.     {
  829.       for (j = 0; j < nsyms; j++)
  830.         if (sympp[j] == *relocs[i]->sym_ptr_ptr)
  831.           break;
  832.       if (j == nsyms)
  833.         abort ();
  834.     }
  835.   }
  836. #endif
  837.  
  838.   if (n)
  839.     bfd_set_reloc (stdoutput, sec, relocs, n);
  840.   else
  841.     bfd_set_section_flags (abfd, sec,
  842.                (bfd_get_section_flags (abfd, sec)
  843.                 & (flagword) ~SEC_RELOC));
  844.  
  845. #ifdef DEBUG3
  846.   {
  847.     int i;
  848.     arelent *r;
  849.     asymbol *s;
  850.     fprintf (stderr, "relocs for sec %s\n", sec->name);
  851.     for (i = 0; i < n; i++)
  852.       {
  853.     r = relocs[i];
  854.     s = *r->sym_ptr_ptr;
  855.     fprintf (stderr, "  reloc %2d @%08x off %4x : sym %-10s addend %x\n",
  856.          i, r, r->address, s->name, r->addend);
  857.       }
  858.   }
  859. #endif
  860. }
  861.  
  862. static void
  863. write_contents (abfd, sec, xxx)
  864.      bfd *abfd;
  865.      asection *sec;
  866.      PTR xxx;
  867. {
  868.   segment_info_type *seginfo = seg_info (sec);
  869.   unsigned long offset = 0;
  870.   fragS *f;
  871.  
  872.   /* Write out the frags.  */
  873.   if (seginfo == NULL
  874.       || ! (bfd_get_section_flags (abfd, sec) & SEC_HAS_CONTENTS))
  875.     return;
  876.  
  877.   for (f = seginfo->frchainP->frch_root;
  878.        f;
  879.        f = f->fr_next)
  880.     {
  881.       int x;
  882.       unsigned long fill_size;
  883.       char *fill_literal;
  884.       long count;
  885.  
  886.       assert (f->fr_type == rs_fill);
  887.       if (f->fr_fix)
  888.     {
  889.       x = bfd_set_section_contents (stdoutput, sec,
  890.                     f->fr_literal, (file_ptr) offset,
  891.                     (bfd_size_type) f->fr_fix);
  892.       if (x == false)
  893.         {
  894.           bfd_perror (stdoutput->filename);
  895.           as_perror ("FATAL: Can't write %s", stdoutput->filename);
  896.           exit (EXIT_FAILURE);
  897.         }
  898.       offset += f->fr_fix;
  899.     }
  900.       fill_literal = f->fr_literal + f->fr_fix;
  901.       fill_size = f->fr_var;
  902.       count = f->fr_offset;
  903.       assert (count >= 0);
  904.       if (fill_size && count)
  905. #ifdef BFD_FAST_SECTION_FILL
  906.     {
  907.       char buf[256];
  908.       if (fill_size > sizeof(buf)) {
  909.         /* Do it the old way. Can this ever happen? */
  910.     while (count--)
  911.       {
  912.         x = bfd_set_section_contents (stdoutput, sec,
  913.                       fill_literal, (file_ptr) offset,
  914.                       (bfd_size_type) fill_size);
  915.         if (x == false)
  916.           {
  917.         bfd_perror (stdoutput->filename);
  918.         as_perror ("FATAL: Can't write %s", stdoutput->filename);
  919.         exit (EXIT_FAILURE);
  920.           }
  921.         offset += fill_size;
  922.       }
  923.     }
  924.       else {
  925.         /* Build a buffer full of fill objects and output it as
  926.          * often as necessary. This saves on the overhead of potentially
  927.          * lots of bfd_set_section_contents calls.
  928.          */
  929.         int n_per_buf, bytes, i;
  930.         if (fill_size == 1)
  931.           {
  932.         n_per_buf = sizeof (buf);
  933.         memset (buf, *fill_literal, n_per_buf);
  934.           }
  935.         else
  936.           {
  937.         char *bufp;
  938.         n_per_buf = sizeof(buf)/fill_size;
  939.         for (i = n_per_buf, bufp = buf; i; i--, bufp += fill_size)
  940.           memcpy(bufp, fill_literal, fill_size);
  941.           }
  942.         for (; count > 0; count -= n_per_buf)
  943.           {
  944.         n_per_buf = n_per_buf > count ? count : n_per_buf;
  945.         x = bfd_set_section_contents (stdoutput, sec,
  946.                           buf, (file_ptr) offset,
  947.                           (bfd_size_type) n_per_buf * fill_size);
  948.         assert (x == true);
  949.         offset += n_per_buf * fill_size;
  950.           }
  951.       }
  952.     }
  953. #else
  954.     while (count--)
  955.       {
  956.         x = bfd_set_section_contents (stdoutput, sec,
  957.                       fill_literal, (file_ptr) offset,
  958.                       (bfd_size_type) fill_size);
  959.         assert (x == true);
  960.         offset += fill_size;
  961.       }
  962. #endif
  963.     }
  964. }
  965. #endif
  966.  
  967. #if defined(BFD_ASSEMBLER) || (!defined (BFD) && !defined(OBJ_AOUT))
  968. static void
  969. merge_data_into_text ()
  970. {
  971. #if defined(BFD_ASSEMBLER) || defined(MANY_SEGMENTS)
  972.   seg_info (text_section)->frchainP->frch_last->fr_next =
  973.     seg_info (data_section)->frchainP->frch_root;
  974.   seg_info (text_section)->frchainP->frch_last =
  975.     seg_info (data_section)->frchainP->frch_last;
  976.   seg_info (data_section)->frchainP = 0;
  977. #else
  978.   fixS *tmp;
  979.  
  980.   text_last_frag->fr_next = data_frag_root;
  981.   text_last_frag = data_last_frag;
  982.   data_last_frag = NULL;
  983.   data_frag_root = NULL;
  984.   if (text_fix_root)
  985.     {
  986.       for (tmp = text_fix_root; tmp->fx_next; tmp = tmp->fx_next);;
  987.       tmp->fx_next = data_fix_root;
  988.       text_fix_tail = data_fix_tail;
  989.     }
  990.   else
  991.     text_fix_root = data_fix_root;
  992.   data_fix_root = NULL;
  993. #endif
  994. }
  995. #endif /* BFD_ASSEMBLER || (! BFD && ! OBJ_AOUT) */
  996.  
  997. #if !defined (BFD_ASSEMBLER) && !defined (BFD)
  998. static void
  999. relax_and_size_all_segments ()
  1000. {
  1001.   fragS *fragP;
  1002.  
  1003.   relax_segment (text_frag_root, SEG_TEXT);
  1004.   relax_segment (data_frag_root, SEG_DATA);
  1005.   relax_segment (bss_frag_root, SEG_BSS);
  1006.   /*
  1007.    * Now the addresses of frags are correct within the segment.
  1008.    */
  1009.  
  1010.   know (text_last_frag->fr_type == rs_fill && text_last_frag->fr_offset == 0);
  1011.   H_SET_TEXT_SIZE (&headers, text_last_frag->fr_address);
  1012.   text_last_frag->fr_address = H_GET_TEXT_SIZE (&headers);
  1013.  
  1014.   /*
  1015.    * Join the 2 segments into 1 huge segment.
  1016.    * To do this, re-compute every rn_address in the SEG_DATA frags.
  1017.    * Then join the data frags after the text frags.
  1018.    *
  1019.    * Determine a_data [length of data segment].
  1020.    */
  1021.   if (data_frag_root)
  1022.     {
  1023.       register relax_addressT slide;
  1024.  
  1025.       know ((text_last_frag->fr_type == rs_fill) && (text_last_frag->fr_offset == 0));
  1026.  
  1027.       H_SET_DATA_SIZE (&headers, data_last_frag->fr_address);
  1028.       data_last_frag->fr_address = H_GET_DATA_SIZE (&headers);
  1029.       slide = H_GET_TEXT_SIZE (&headers);    /* & in file of the data segment. */
  1030. #ifdef OBJ_BOUT
  1031. #define RoundUp(N,S) (((N)+(S)-1)&-(S))
  1032.       /* For b.out: If the data section has a strict alignment
  1033.      requirement, its load address in the .o file will be
  1034.      rounded up from the size of the text section.  These
  1035.      two values are *not* the same!  Similarly for the bss
  1036.      section....  */
  1037.       slide = RoundUp (slide, 1 << section_alignment[SEG_DATA]);
  1038. #endif
  1039.  
  1040.       for (fragP = data_frag_root; fragP; fragP = fragP->fr_next)
  1041.     {
  1042.       fragP->fr_address += slide;
  1043.     }            /* for each data frag */
  1044.  
  1045.       know (text_last_frag != 0);
  1046.       text_last_frag->fr_next = data_frag_root;
  1047.     }
  1048.   else
  1049.     {
  1050.       H_SET_DATA_SIZE (&headers, 0);
  1051.     }
  1052.  
  1053. #ifdef OBJ_BOUT
  1054.   /* See above comments on b.out data section address.  */
  1055.   {
  1056.     long bss_vma;
  1057.     if (data_last_frag == 0)
  1058.       bss_vma = H_GET_TEXT_SIZE (&headers);
  1059.     else
  1060.       bss_vma = data_last_frag->fr_address;
  1061.     bss_vma = RoundUp (bss_vma, 1 << section_alignment[SEG_BSS]);
  1062.     bss_address_frag.fr_address = bss_vma;
  1063.   }
  1064. #else /* ! OBJ_BOUT */
  1065.   bss_address_frag.fr_address = (H_GET_TEXT_SIZE (&headers) +
  1066.                  H_GET_DATA_SIZE (&headers));
  1067.  
  1068. #endif /* ! OBJ_BOUT */
  1069.  
  1070.   /* Slide all the frags */
  1071.   if (bss_frag_root)
  1072.     {
  1073.       relax_addressT slide = bss_address_frag.fr_address;
  1074.  
  1075.       for (fragP = bss_frag_root; fragP; fragP = fragP->fr_next)
  1076.     {
  1077.       fragP->fr_address += slide;
  1078.     }            /* for each bss frag */
  1079.     }
  1080.  
  1081.   if (bss_last_frag)
  1082.     H_SET_BSS_SIZE (&headers,
  1083.             bss_last_frag->fr_address - bss_frag_root->fr_address);
  1084.   else
  1085.     H_SET_BSS_SIZE (&headers, 0);
  1086. }
  1087. #endif /* ! BFD_ASSEMBLER && ! BFD */
  1088.  
  1089. #if defined (BFD_ASSEMBLER) || !defined (BFD)
  1090.  
  1091. #ifdef BFD_ASSEMBLER
  1092. static void
  1093. set_symtab ()
  1094. {
  1095.   int nsyms;
  1096.   asymbol **asympp;
  1097.   symbolS *symp;
  1098.   boolean result;
  1099.   extern PTR bfd_alloc PARAMS ((bfd *, size_t));
  1100.  
  1101.   /* Count symbols.  We can't rely on a count made by the loop in
  1102.      write_object_file, because *_frob_file may add a new symbol or
  1103.      two.  */
  1104.   nsyms = 0;
  1105.   for (symp = symbol_rootP; symp; symp = symbol_next (symp))
  1106.     nsyms++;
  1107.  
  1108.   if (nsyms)
  1109.     {
  1110.       int i;
  1111.  
  1112.       asympp = (asymbol **) bfd_alloc (stdoutput,
  1113.                        nsyms * sizeof (asymbol *));
  1114.       symp = symbol_rootP;
  1115.       for (i = 0; i < nsyms; i++, symp = symbol_next (symp))
  1116.     {
  1117.       asympp[i] = symp->bsym;
  1118.       symp->written = 1;
  1119.     }
  1120.     }
  1121.   else
  1122.     asympp = 0;
  1123.   result = bfd_set_symtab (stdoutput, asympp, nsyms);
  1124.   assert (result == true);
  1125.   symbol_table_frozen = 1;
  1126. }
  1127. #endif
  1128.  
  1129. void 
  1130. write_object_file ()
  1131. {
  1132.   struct frchain *frchainP;    /* Track along all frchains. */
  1133. #if ! defined (BFD_ASSEMBLER) || ! defined (WORKING_DOT_WORD)
  1134.   fragS *fragP;            /* Track along all frags. */
  1135. #endif
  1136.  
  1137.   /* Do we really want to write it?  */
  1138.   {
  1139.     int n_warns, n_errs;
  1140.     n_warns = had_warnings ();
  1141.     n_errs = had_errors ();
  1142.     /* The -Z flag indicates that an object file should be generated,
  1143.        regardless of warnings and errors.  */
  1144.     if (flag_always_generate_output)
  1145.       {
  1146.     if (n_warns || n_errs)
  1147.       as_warn ("%d error%s, %d warning%s, generating bad object file.\n",
  1148.            n_errs, n_errs == 1 ? "" : "s",
  1149.            n_warns, n_warns == 1 ? "" : "s");
  1150.       }
  1151.     else
  1152.       {
  1153.     if (n_errs)
  1154.       as_fatal ("%d error%s, %d warning%s, no object file generated.\n",
  1155.             n_errs, n_errs == 1 ? "" : "s",
  1156.             n_warns, n_warns == 1 ? "" : "s");
  1157.       }
  1158.   }
  1159.  
  1160. #ifdef    OBJ_VMS
  1161.   /* Under VMS we try to be compatible with VAX-11 "C".  Thus, we call
  1162.      a routine to check for the definition of the procedure "_main",
  1163.      and if so -- fix it up so that it can be program entry point. */
  1164.   VMS_Check_For_Main ();
  1165. #endif /* VMS */
  1166.  
  1167.   /* After every sub-segment, we fake an ".align ...". This conforms to
  1168.      BSD4.2 brane-damage. We then fake ".fill 0" because that is the kind of
  1169.      frag that requires least thought. ".align" frags like to have a
  1170.      following frag since that makes calculating their intended length
  1171.      trivial.
  1172.  
  1173.      @@ Is this really necessary??  */
  1174. #ifndef SUB_SEGMENT_ALIGN
  1175. #ifdef BFD_ASSEMBLER
  1176. #define SUB_SEGMENT_ALIGN(SEG) (0)
  1177. #else
  1178. #define SUB_SEGMENT_ALIGN(SEG) (2)
  1179. #endif
  1180. #endif
  1181.   for (frchainP = frchain_root; frchainP; frchainP = frchainP->frch_next)
  1182.     {
  1183.       subseg_set (frchainP->frch_seg, frchainP->frch_subseg);
  1184.       frag_align (SUB_SEGMENT_ALIGN (now_seg), NOP_OPCODE);
  1185.       /* frag_align will have left a new frag.
  1186.      Use this last frag for an empty ".fill".
  1187.  
  1188.      For this segment ...
  1189.      Create a last frag. Do not leave a "being filled in frag".  */
  1190.       frag_wane (frag_now);
  1191.       frag_now->fr_fix = 0;
  1192.       know (frag_now->fr_next == NULL);
  1193.     }
  1194.  
  1195.   /* From now on, we don't care about sub-segments.  Build one frag chain
  1196.      for each segment. Linked thru fr_next.  */
  1197.  
  1198. #ifdef BFD_ASSEMBLER
  1199.   /* Remove the sections created by gas for its own purposes.  */
  1200.   {
  1201.     asection **seclist, *sec;
  1202.     seclist = &stdoutput->sections;
  1203.     while (seclist && *seclist)
  1204.       {
  1205.     sec = *seclist;
  1206.     while (sec == reg_section || sec == expr_section)
  1207.       {
  1208.         sec = sec->next;
  1209.         *seclist = sec;
  1210.         stdoutput->section_count--;
  1211.         if (!sec)
  1212.           break;
  1213.       }
  1214.     if (*seclist)
  1215.       seclist = &(*seclist)->next;
  1216.       }
  1217.   }
  1218.  
  1219.   bfd_map_over_sections (stdoutput, chain_frchains_together, (char *) 0);
  1220. #else
  1221.   remove_subsegs (frchain_root, SEG_TEXT, &text_frag_root, &text_last_frag);
  1222.   remove_subsegs (data0_frchainP, SEG_DATA, &data_frag_root, &data_last_frag);
  1223.   remove_subsegs (bss0_frchainP, SEG_BSS, &bss_frag_root, &bss_last_frag);
  1224. #endif
  1225.  
  1226.   /* We have two segments. If user gave -R flag, then we must put the
  1227.      data frags into the text segment. Do this before relaxing so
  1228.      we know to take advantage of -R and make shorter addresses.  */
  1229. #if !defined (OBJ_AOUT) || defined (BFD_ASSEMBLER)
  1230.   if (flag_readonly_data_in_text)
  1231.     {
  1232.       merge_data_into_text ();
  1233.     }
  1234. #endif
  1235.  
  1236. #ifdef BFD_ASSEMBLER
  1237.   bfd_map_over_sections (stdoutput, relax_and_size_seg, (char *) 0);
  1238. #else
  1239.   relax_and_size_all_segments ();
  1240. #endif /* BFD_ASSEMBLER */
  1241.  
  1242. #ifndef BFD_ASSEMBLER
  1243.   /*
  1244.    *
  1245.    * Crawl the symbol chain.
  1246.    *
  1247.    * For each symbol whose value depends on a frag, take the address of
  1248.    * that frag and subsume it into the value of the symbol.
  1249.    * After this, there is just one way to lookup a symbol value.
  1250.    * Values are left in their final state for object file emission.
  1251.    * We adjust the values of 'L' local symbols, even if we do
  1252.    * not intend to emit them to the object file, because their values
  1253.    * are needed for fix-ups.
  1254.    *
  1255.    * Unless we saw a -L flag, remove all symbols that begin with 'L'
  1256.    * from the symbol chain.  (They are still pointed to by the fixes.)
  1257.    *
  1258.    * Count the remaining symbols.
  1259.    * Assign a symbol number to each symbol.
  1260.    * Count the number of string-table chars we will emit.
  1261.    * Put this info into the headers as appropriate.
  1262.    *
  1263.    */
  1264.   know (zero_address_frag.fr_address == 0);
  1265.   string_byte_count = sizeof (string_byte_count);
  1266.  
  1267.   obj_crawl_symbol_chain (&headers);
  1268.  
  1269.   if (string_byte_count == sizeof (string_byte_count))
  1270.     string_byte_count = 0;
  1271.  
  1272.   H_SET_STRING_SIZE (&headers, string_byte_count);
  1273.  
  1274.   /*
  1275.    * Addresses of frags now reflect addresses we use in the object file.
  1276.    * Symbol values are correct.
  1277.    * Scan the frags, converting any ".org"s and ".align"s to ".fill"s.
  1278.    * Also converting any machine-dependent frags using md_convert_frag();
  1279.    */
  1280.   subseg_change (SEG_TEXT, 0);
  1281.  
  1282.   for (fragP = text_frag_root; fragP; fragP = fragP->fr_next)
  1283.     {
  1284.       cvt_frag_to_fill (&headers, fragP);
  1285.  
  1286.       /* Some assert macros don't work with # directives mixed in.  */
  1287. #ifndef NDEBUG
  1288.       if (!(fragP->fr_next == NULL
  1289. #ifdef OBJ_BOUT
  1290.         || fragP->fr_next == data_frag_root
  1291. #endif
  1292.         || ((fragP->fr_next->fr_address - fragP->fr_address)
  1293.         == (fragP->fr_fix + fragP->fr_offset * fragP->fr_var))))
  1294.     abort ();
  1295. #endif
  1296.     }
  1297. #endif /* ! BFD_ASSEMBLER */
  1298.  
  1299. #ifndef WORKING_DOT_WORD
  1300.   {
  1301.     struct broken_word *lie;
  1302.     struct broken_word **prevP;
  1303.  
  1304.     prevP = &broken_words;
  1305.     for (lie = broken_words; lie; lie = lie->next_broken_word)
  1306.       if (!lie->added)
  1307.     {
  1308.       expressionS exp;
  1309.  
  1310.       exp.X_op = O_subtract;
  1311.       exp.X_add_symbol = lie->add;
  1312.       exp.X_op_symbol = lie->sub;
  1313.       exp.X_add_number = lie->addnum;
  1314. #ifdef BFD_ASSEMBLER
  1315. #ifdef TC_CONS_FIX_NEW
  1316.       TC_CONS_FIX_NEW (lie->frag,
  1317.                lie->word_goes_here - lie->frag->fr_literal,
  1318.                2, &exp);
  1319. #else
  1320.       fix_new_exp (lie->frag,
  1321.                lie->word_goes_here - lie->frag->fr_literal,
  1322.                2, &exp, 0, BFD_RELOC_NONE);
  1323. #endif
  1324. #else
  1325. #if defined(TC_SPARC) || defined(TC_A29K) || defined(NEED_FX_R_TYPE)
  1326.       fix_new_exp (lie->frag,
  1327.                lie->word_goes_here - lie->frag->fr_literal,
  1328.                2, &exp, 0, NO_RELOC);
  1329. #else
  1330. #ifdef TC_NS32K
  1331.       fix_new_ns32k_exp (lie->frag,
  1332.                  lie->word_goes_here - lie->frag->fr_literal,
  1333.                  2, &exp, 0, 0, 2, 0, 0);
  1334. #else
  1335.       fix_new_exp (lie->frag,
  1336.                lie->word_goes_here - lie->frag->fr_literal,
  1337.                2, &exp, 0, 0);
  1338. #endif /* TC_NS32K */
  1339. #endif /* TC_SPARC|TC_A29K|NEED_FX_R_TYPE */
  1340. #endif /* BFD_ASSEMBLER */
  1341.       *prevP = lie->next_broken_word;
  1342.     }
  1343.       else
  1344.     prevP = &(lie->next_broken_word);
  1345.  
  1346.     for (lie = broken_words; lie;)
  1347.       {
  1348.     struct broken_word *untruth;
  1349.     char *table_ptr;
  1350.     addressT table_addr;
  1351.     addressT from_addr, to_addr;
  1352.     int n, m;
  1353.  
  1354.     fragP = lie->dispfrag;
  1355.  
  1356.     /* Find out how many broken_words go here.  */
  1357.     n = 0;
  1358.     for (untruth = lie; untruth && untruth->dispfrag == fragP; untruth = untruth->next_broken_word)
  1359.       if (untruth->added == 1)
  1360.         n++;
  1361.  
  1362.     table_ptr = lie->dispfrag->fr_opcode;
  1363.     table_addr = lie->dispfrag->fr_address + (table_ptr - lie->dispfrag->fr_literal);
  1364.     /* Create the jump around the long jumps.  This is a short
  1365.        jump from table_ptr+0 to table_ptr+n*long_jump_size.  */
  1366.     from_addr = table_addr;
  1367.     to_addr = table_addr + md_short_jump_size + n * md_long_jump_size;
  1368.     md_create_short_jump (table_ptr, from_addr, to_addr, lie->dispfrag, lie->add);
  1369.     table_ptr += md_short_jump_size;
  1370.     table_addr += md_short_jump_size;
  1371.  
  1372.     for (m = 0; lie && lie->dispfrag == fragP; m++, lie = lie->next_broken_word)
  1373.       {
  1374.         if (lie->added == 2)
  1375.           continue;
  1376.         /* Patch the jump table */
  1377.         /* This is the offset from ??? to table_ptr+0 */
  1378.         to_addr = table_addr - S_GET_VALUE (lie->sub);
  1379. #ifdef BFD_ASSEMBLER
  1380.         to_addr -= lie->sub->sy_frag->fr_address;
  1381. #endif
  1382.         md_number_to_chars (lie->word_goes_here, to_addr, 2);
  1383.         for (untruth = lie->next_broken_word; untruth && untruth->dispfrag == fragP; untruth = untruth->next_broken_word)
  1384.           {
  1385.         if (untruth->use_jump == lie)
  1386.           md_number_to_chars (untruth->word_goes_here, to_addr, 2);
  1387.           }
  1388.  
  1389.         /* Install the long jump */
  1390.         /* this is a long jump from table_ptr+0 to the final target */
  1391.         from_addr = table_addr;
  1392.         to_addr = S_GET_VALUE (lie->add) + lie->addnum;
  1393. #ifdef BFD_ASSEMBLER
  1394.         to_addr += lie->add->sy_frag->fr_address;
  1395. #endif
  1396.         md_create_long_jump (table_ptr, from_addr, to_addr, lie->dispfrag, lie->add);
  1397.         table_ptr += md_long_jump_size;
  1398.         table_addr += md_long_jump_size;
  1399.       }
  1400.       }
  1401.   }
  1402. #endif /* not WORKING_DOT_WORD */
  1403.  
  1404. #ifndef BFD_ASSEMBLER
  1405. #ifndef    OBJ_VMS
  1406.   {                /* not vms */
  1407.     long object_file_size;
  1408.     /*
  1409.      * Scan every FixS performing fixups. We had to wait until now to do
  1410.      * this because md_convert_frag() may have made some fixSs.
  1411.      */
  1412.     int trsize, drsize;
  1413.  
  1414.     subseg_change (SEG_TEXT, 0);
  1415.     trsize = md_reloc_size * fixup_segment (text_fix_root, SEG_TEXT);
  1416.     subseg_change (SEG_DATA, 0);
  1417.     drsize = md_reloc_size * fixup_segment (data_fix_root, SEG_DATA);
  1418.     H_SET_RELOCATION_SIZE (&headers, trsize, drsize);
  1419.  
  1420.     /* FIXME move this stuff into the pre-write-hook */
  1421.     H_SET_MAGIC_NUMBER (&headers, magic_number_for_object_file);
  1422.     H_SET_ENTRY_POINT (&headers, 0);
  1423.  
  1424.     obj_pre_write_hook (&headers);    /* extra coff stuff */
  1425.  
  1426.     object_file_size = H_GET_FILE_SIZE (&headers);
  1427.     next_object_file_charP = the_object_file = xmalloc (object_file_size);
  1428.  
  1429.     output_file_create (out_file_name);
  1430.  
  1431.     obj_header_append (&next_object_file_charP, &headers);
  1432.  
  1433.     know ((next_object_file_charP - the_object_file) == H_GET_HEADER_SIZE (&headers));
  1434.  
  1435.     /*
  1436.      * Emit code.
  1437.      */
  1438.     for (fragP = text_frag_root; fragP; fragP = fragP->fr_next)
  1439.       {
  1440.     register long count;
  1441.     register char *fill_literal;
  1442.     register long fill_size;
  1443.  
  1444.     know (fragP->fr_type == rs_fill);
  1445.     append (&next_object_file_charP, fragP->fr_literal, (unsigned long) fragP->fr_fix);
  1446.     fill_literal = fragP->fr_literal + fragP->fr_fix;
  1447.     fill_size = fragP->fr_var;
  1448.     know (fragP->fr_offset >= 0);
  1449.  
  1450.     for (count = fragP->fr_offset; count; count--)
  1451.       {
  1452.         append (&next_object_file_charP, fill_literal, (unsigned long) fill_size);
  1453.       }            /* for each  */
  1454.  
  1455.       }                /* for each code frag. */
  1456.  
  1457.     know ((next_object_file_charP - the_object_file) == (H_GET_HEADER_SIZE (&headers) + H_GET_TEXT_SIZE (&headers) + H_GET_DATA_SIZE (&headers)));
  1458.  
  1459.     /*
  1460.      * Emit relocations.
  1461.      */
  1462.     obj_emit_relocations (&next_object_file_charP, text_fix_root, (relax_addressT) 0);
  1463.     know ((next_object_file_charP - the_object_file) == (H_GET_HEADER_SIZE (&headers) + H_GET_TEXT_SIZE (&headers) + H_GET_DATA_SIZE (&headers) + H_GET_TEXT_RELOCATION_SIZE (&headers)));
  1464. #ifdef TC_I960
  1465.     /* Make addresses in data relocation directives relative to beginning of
  1466.      * first data fragment, not end of last text fragment:  alignment of the
  1467.      * start of the data segment may place a gap between the segments.
  1468.      */
  1469.     obj_emit_relocations (&next_object_file_charP, data_fix_root, data0_frchainP->frch_root->fr_address);
  1470. #else /* TC_I960 */
  1471.     obj_emit_relocations (&next_object_file_charP, data_fix_root, text_last_frag->fr_address);
  1472. #endif /* TC_I960 */
  1473.  
  1474.     know ((next_object_file_charP - the_object_file) == (H_GET_HEADER_SIZE (&headers) + H_GET_TEXT_SIZE (&headers) + H_GET_DATA_SIZE (&headers) + H_GET_TEXT_RELOCATION_SIZE (&headers) + H_GET_DATA_RELOCATION_SIZE (&headers)));
  1475.  
  1476.     /*
  1477.      * Emit line number entries.
  1478.      */
  1479.     OBJ_EMIT_LINENO (&next_object_file_charP, lineno_rootP, the_object_file);
  1480.     know ((next_object_file_charP - the_object_file) == (H_GET_HEADER_SIZE (&headers) + H_GET_TEXT_SIZE (&headers) + H_GET_DATA_SIZE (&headers) + H_GET_TEXT_RELOCATION_SIZE (&headers) + H_GET_DATA_RELOCATION_SIZE (&headers) + H_GET_LINENO_SIZE (&headers)));
  1481.  
  1482.     /*
  1483.      * Emit symbols.
  1484.      */
  1485.     obj_emit_symbols (&next_object_file_charP, symbol_rootP);
  1486.     know ((next_object_file_charP - the_object_file) == (H_GET_HEADER_SIZE (&headers) + H_GET_TEXT_SIZE (&headers) + H_GET_DATA_SIZE (&headers) + H_GET_TEXT_RELOCATION_SIZE (&headers) + H_GET_DATA_RELOCATION_SIZE (&headers) + H_GET_LINENO_SIZE (&headers) + H_GET_SYMBOL_TABLE_SIZE (&headers)));
  1487.  
  1488.     /*
  1489.      * Emit strings.
  1490.      */
  1491.  
  1492.     if (string_byte_count > 0)
  1493.       {
  1494.     obj_emit_strings (&next_object_file_charP);
  1495.       }                /* only if we have a string table */
  1496.  
  1497. #ifdef BFD_HEADERS
  1498.     bfd_seek (stdoutput, 0, 0);
  1499.     bfd_write (the_object_file, 1, object_file_size, stdoutput);
  1500. #else
  1501.  
  1502.     /* Write the data to the file */
  1503.     output_file_append (the_object_file, object_file_size, out_file_name);
  1504. #endif
  1505.   }                /* non vms output */
  1506. #else /* VMS */
  1507.   /*
  1508.    *    Now do the VMS-dependent part of writing the object file
  1509.    */
  1510.   VMS_write_object_file (H_GET_TEXT_SIZE (&headers),
  1511.              H_GET_DATA_SIZE (&headers),
  1512.              H_GET_BSS_SIZE (&headers),
  1513.              text_frag_root, data_frag_root);
  1514. #endif /* VMS */
  1515. #else /* BFD_ASSEMBLER */
  1516.  
  1517.   /* Resolve symbol values.  This needs to be done before processing
  1518.      the relocations.  */
  1519.   if (symbol_rootP)
  1520.     {
  1521.       symbolS *symp;
  1522.  
  1523.       for (symp = symbol_rootP; symp; symp = symbol_next (symp))
  1524.     if (!symp->sy_resolved)
  1525.       resolve_symbol_value (symp);
  1526.     }
  1527.  
  1528.   bfd_map_over_sections (stdoutput, adjust_reloc_syms, (char *)0);
  1529.  
  1530.   /* Set up symbol table, and write it out.  */
  1531.   if (symbol_rootP)
  1532.     {
  1533.       symbolS *symp;
  1534.  
  1535.       for (symp = symbol_rootP; symp; symp = symbol_next (symp))
  1536.     {
  1537.       int punt = 0;
  1538.  
  1539.       /* Do it again, because adjust_reloc_syms might introduce
  1540.          more symbols.  They'll probably only be section symbols,
  1541.          but they'll still need to have the values computed.  */
  1542.       if (! symp->sy_resolved)
  1543.         {
  1544.           if (symp->sy_value.X_op == O_constant)
  1545.         {
  1546.           /* This is the normal case; skip the call.  */
  1547.           S_SET_VALUE (symp,
  1548.                    (S_GET_VALUE (symp)
  1549.                 + symp->sy_frag->fr_address));
  1550.           symp->sy_resolved = 1;
  1551.         }
  1552.           else
  1553.         resolve_symbol_value (symp);
  1554.         }
  1555.  
  1556.       /* So far, common symbols have been treated like undefined symbols.
  1557.          Put them in the common section now.  */
  1558.       if (S_IS_DEFINED (symp) == 0
  1559.           && S_GET_VALUE (symp) != 0)
  1560.         S_SET_SEGMENT (symp, bfd_com_section_ptr);
  1561. #if 0
  1562.       printf ("symbol `%s'\n\t@%x: value=%d flags=%x seg=%s\n",
  1563.           S_GET_NAME (symp), symp,
  1564.           S_GET_VALUE (symp),
  1565.           symp->bsym->flags,
  1566.           segment_name (symp->bsym->section));
  1567. #endif
  1568.  
  1569. #ifdef obj_frob_symbol
  1570.       obj_frob_symbol (symp, punt);
  1571. #endif
  1572. #ifdef tc_frob_symbol
  1573.       if (! punt || symp->sy_used_in_reloc)
  1574.         tc_frob_symbol (symp, punt);
  1575. #endif
  1576.  
  1577.       /* If we don't want to keep this symbol, splice it out of
  1578.          the chain now.  If EMIT_SECTION_SYMBOLS is 0, we never
  1579.          want section symbols.  Otherwise, we skip local symbols
  1580.          and symbols that the frob_symbol macros told us to punt,
  1581.          but we keep such symbols if they are used in relocs.  */
  1582.       if ((! EMIT_SECTION_SYMBOLS
  1583.            && (symp->bsym->flags & BSF_SECTION_SYM) != 0)
  1584.           /* Note that S_IS_EXTERN and S_IS_LOCAL are not always
  1585.          opposites.  Sometimes the former checks flags and the
  1586.          latter examines the name...  */
  1587.           || (!S_IS_EXTERN (symp)
  1588.           && (S_IS_LOCAL (symp) || punt)
  1589.           && ! symp->sy_used_in_reloc))
  1590.         {
  1591.           symbol_remove (symp, &symbol_rootP, &symbol_lastP);
  1592.           /* After symbol_remove, symbol_next(symp) still returns
  1593.          the one that came after it in the chain.  So we don't
  1594.          need to do any extra cleanup work here.  */
  1595.  
  1596.           continue;
  1597.         }
  1598.  
  1599.       /* Make sure we really got a value for the symbol.  */
  1600.       if (! symp->sy_resolved)
  1601.         {
  1602.           as_bad ("can't resolve value for symbol \"%s\"",
  1603.               S_GET_NAME (symp));
  1604.           symp->sy_resolved = 1;
  1605.         }
  1606.  
  1607.       /* Set the value into the BFD symbol.  Up til now the value
  1608.          has only been kept in the gas symbolS struct.  */
  1609.       symp->bsym->value = S_GET_VALUE (symp);
  1610.     }
  1611.     }
  1612.  
  1613.   /* Now do any format-specific adjustments to the symbol table, such
  1614.      as adding file symbols.  */
  1615. #ifdef obj_adjust_symtab
  1616.   obj_adjust_symtab ();
  1617. #endif
  1618.  
  1619.   /* Now that all the sizes are known, and contents correct, we can
  1620.      start writing to the file.  */
  1621.   set_symtab ();
  1622.  
  1623.   /* If *_frob_file changes the symbol value at this point, it is
  1624.      responsible for moving the changed value into symp->bsym->value
  1625.      as well.  Hopefully all symbol value changing can be done in
  1626.      *_frob_symbol.  */
  1627. #ifdef tc_frob_file
  1628.   tc_frob_file ();
  1629. #endif
  1630. #ifdef obj_frob_file
  1631.   obj_frob_file ();
  1632. #endif
  1633.  
  1634.   bfd_map_over_sections (stdoutput, write_relocs, (char *) 0);
  1635.  
  1636.   bfd_map_over_sections (stdoutput, write_contents, (char *) 0);
  1637. #endif /* BFD_ASSEMBLER */
  1638. }
  1639. #endif /* ! BFD */
  1640.  
  1641. /*
  1642.  *            relax_segment()
  1643.  *
  1644.  * Now we have a segment, not a crowd of sub-segments, we can make fr_address
  1645.  * values.
  1646.  *
  1647.  * Relax the frags.
  1648.  *
  1649.  * After this, all frags in this segment have addresses that are correct
  1650.  * within the segment. Since segments live in different file addresses,
  1651.  * these frag addresses may not be the same as final object-file addresses.
  1652.  */
  1653.  
  1654. #ifndef md_relax_frag
  1655.  
  1656. /* Subroutines of relax_segment.  */
  1657. static int 
  1658. is_dnrange (f1, f2)
  1659.      struct frag *f1;
  1660.      struct frag *f2;
  1661. {
  1662.   for (; f1; f1 = f1->fr_next)
  1663.     if (f1->fr_next == f2)
  1664.       return 1;
  1665.   return 0;
  1666. }
  1667.  
  1668. #endif /* ! defined (md_relax_frag) */
  1669.  
  1670. /* Relax_align. Advance location counter to next address that has 'alignment'
  1671.    lowest order bits all 0s, return size of adjustment made.  */
  1672. static relax_addressT
  1673. relax_align (address, alignment)
  1674.      register relax_addressT address;    /* Address now. */
  1675.      register int alignment;    /* Alignment (binary). */
  1676. {
  1677.   relax_addressT mask;
  1678.   relax_addressT new_address;
  1679.  
  1680.   mask = ~((~0) << alignment);
  1681.   new_address = (address + mask) & (~mask);
  1682.   if (linkrelax)
  1683.     /* We must provide lots of padding, so the linker can discard it
  1684.        when needed.  The linker will not add extra space, ever.  */
  1685.     new_address += (1 << alignment);
  1686.   return (new_address - address);
  1687. }
  1688.  
  1689. void 
  1690. relax_segment (segment_frag_root, segment)
  1691.      struct frag *segment_frag_root;
  1692.      segT segment;
  1693. {
  1694.   register struct frag *fragP;
  1695.   register relax_addressT address;
  1696. #if !defined (MANY_SEGMENTS) && !defined (BFD_ASSEMBLER)
  1697.   know (segment == SEG_DATA || segment == SEG_TEXT || segment == SEG_BSS);
  1698. #endif
  1699.   /* In case md_estimate_size_before_relax() wants to make fixSs. */
  1700.   subseg_change (segment, 0);
  1701.  
  1702.   /* For each frag in segment: count and store  (a 1st guess of)
  1703.      fr_address.  */
  1704.   address = 0;
  1705.   for (fragP = segment_frag_root; fragP; fragP = fragP->fr_next)
  1706.     {
  1707.       fragP->fr_address = address;
  1708.       address += fragP->fr_fix;
  1709.  
  1710.       switch (fragP->fr_type)
  1711.     {
  1712.     case rs_fill:
  1713.       address += fragP->fr_offset * fragP->fr_var;
  1714.       break;
  1715.  
  1716.     case rs_align:
  1717.       {
  1718.         int offset = relax_align (address, (int) fragP->fr_offset);
  1719.         if (offset % fragP->fr_var != 0)
  1720.           {
  1721.         as_bad ("alignment padding (%d bytes) not a multiple of %ld",
  1722.             offset, (long) fragP->fr_var);
  1723.         offset -= (offset % fragP->fr_var);
  1724.           }
  1725.         address += offset;
  1726.       }
  1727.       break;
  1728.  
  1729.     case rs_org:
  1730.       /* Assume .org is nugatory. It will grow with 1st relax.  */
  1731.       break;
  1732.  
  1733.     case rs_machine_dependent:
  1734.       address += md_estimate_size_before_relax (fragP, segment);
  1735.       break;
  1736.  
  1737. #ifndef WORKING_DOT_WORD
  1738.       /* Broken words don't concern us yet */
  1739.     case rs_broken_word:
  1740.       break;
  1741. #endif
  1742.  
  1743.     default:
  1744.       BAD_CASE (fragP->fr_type);
  1745.       break;
  1746.     }            /* switch(fr_type) */
  1747.     }                /* for each frag in the segment */
  1748.  
  1749.   /* Do relax().  */
  1750.   {
  1751.     long stretch;    /* May be any size, 0 or negative. */
  1752.     /* Cumulative number of addresses we have */
  1753.     /* relaxed this pass. */
  1754.     /* We may have relaxed more than one address. */
  1755.     long stretched;    /* Have we stretched on this pass? */
  1756.     /* This is 'cuz stretch may be zero, when, in fact some piece of code
  1757.        grew, and another shrank.  If a branch instruction doesn't fit anymore,
  1758.        we could be scrod.  */
  1759.  
  1760.     do
  1761.       {
  1762.     stretch = stretched = 0;
  1763.     for (fragP = segment_frag_root; fragP; fragP = fragP->fr_next)
  1764.       {
  1765.         long growth = 0;
  1766.         unsigned long was_address;
  1767.         long offset;
  1768.         symbolS *symbolP;
  1769.         long target;
  1770.         long after;
  1771.  
  1772.         was_address = fragP->fr_address;
  1773.         address = fragP->fr_address += stretch;
  1774.         symbolP = fragP->fr_symbol;
  1775.         offset = fragP->fr_offset;
  1776.  
  1777.         switch (fragP->fr_type)
  1778.           {
  1779.           case rs_fill:    /* .fill never relaxes. */
  1780.         growth = 0;
  1781.         break;
  1782.  
  1783. #ifndef WORKING_DOT_WORD
  1784.         /* JF:  This is RMS's idea.  I do *NOT* want to be blamed
  1785.            for it I do not want to write it.  I do not want to have
  1786.            anything to do with it.  This is not the proper way to
  1787.            implement this misfeature.  */
  1788.           case rs_broken_word:
  1789.         {
  1790.           struct broken_word *lie;
  1791.           struct broken_word *untruth;
  1792.  
  1793.           /* Yes this is ugly (storing the broken_word pointer
  1794.              in the symbol slot).  Still, this whole chunk of
  1795.              code is ugly, and I don't feel like doing anything
  1796.              about it.  Think of it as stubbornness in action.  */
  1797.           growth = 0;
  1798.           for (lie = (struct broken_word *) (fragP->fr_symbol);
  1799.                lie && lie->dispfrag == fragP;
  1800.                lie = lie->next_broken_word)
  1801.             {
  1802.  
  1803.               if (lie->added)
  1804.             continue;
  1805.  
  1806.               offset = (lie->add->sy_frag->fr_address
  1807.                 + S_GET_VALUE (lie->add)
  1808.                 + lie->addnum
  1809.                 - (lie->sub->sy_frag->fr_address
  1810.                    + S_GET_VALUE (lie->sub)));
  1811.               if (offset <= -32768 || offset >= 32767)
  1812.             {
  1813.               if (flag_warn_displacement)
  1814.                 {
  1815.                   char buf[50];
  1816.                   sprint_value (buf, (addressT) lie->addnum);
  1817.                   as_warn (".word %s-%s+%s didn't fit",
  1818.                        S_GET_NAME (lie->add),
  1819.                        S_GET_NAME (lie->sub),
  1820.                        buf);
  1821.                 }
  1822.               lie->added = 1;
  1823.               if (fragP->fr_subtype == 0)
  1824.                 {
  1825.                   fragP->fr_subtype++;
  1826.                   growth += md_short_jump_size;
  1827.                 }
  1828.               for (untruth = lie->next_broken_word;
  1829.                    untruth && untruth->dispfrag == lie->dispfrag;
  1830.                    untruth = untruth->next_broken_word)
  1831.                 if ((untruth->add->sy_frag == lie->add->sy_frag)
  1832.                 && S_GET_VALUE (untruth->add) == S_GET_VALUE (lie->add))
  1833.                   {
  1834.                 untruth->added = 2;
  1835.                 untruth->use_jump = lie;
  1836.                   }
  1837.               growth += md_long_jump_size;
  1838.             }
  1839.             }
  1840.  
  1841.           break;
  1842.         }        /* case rs_broken_word */
  1843. #endif
  1844.           case rs_align:
  1845.         growth = (relax_align ((relax_addressT) (address
  1846.                              + fragP->fr_fix),
  1847.                        (int) offset)
  1848.               - relax_align ((relax_addressT) (was_address
  1849.                                + fragP->fr_fix),
  1850.                      (int) offset));
  1851.         break;
  1852.  
  1853.           case rs_org:
  1854.         target = offset;
  1855.  
  1856.         if (symbolP)
  1857.           {
  1858. #if !defined (MANY_SEGMENTS) && !defined (BFD_ASSEMBLER)
  1859.             know ((S_GET_SEGMENT (symbolP) == SEG_ABSOLUTE)
  1860.               || (S_GET_SEGMENT (symbolP) == SEG_DATA)
  1861.               || (S_GET_SEGMENT (symbolP) == SEG_TEXT)
  1862.               || S_GET_SEGMENT (symbolP) == SEG_BSS);
  1863.             know (symbolP->sy_frag);
  1864.             know (!(S_GET_SEGMENT (symbolP) == SEG_ABSOLUTE)
  1865.               || (symbolP->sy_frag == &zero_address_frag));
  1866. #endif
  1867.             target += S_GET_VALUE (symbolP)
  1868.               + symbolP->sy_frag->fr_address;
  1869.           }        /* if we have a symbol */
  1870.  
  1871.         know (fragP->fr_next);
  1872.         after = fragP->fr_next->fr_address;
  1873.         growth = ((target - after) > 0) ? (target - after) : 0;
  1874.         /* Growth may be negative, but variable part of frag
  1875.            cannot have fewer than 0 chars.  That is, we can't
  1876.            .org backwards. */
  1877.  
  1878.         growth -= stretch;    /* This is an absolute growth factor */
  1879.         break;
  1880.  
  1881.           case rs_machine_dependent:
  1882. #ifdef md_relax_frag
  1883.         growth = md_relax_frag (fragP, stretch);
  1884. #else
  1885.         /* The default way to relax a frag is to look through
  1886.            md_relax_table.  */
  1887.         {
  1888.           const relax_typeS *this_type;
  1889.           const relax_typeS *start_type;
  1890.           relax_substateT next_state;
  1891.           relax_substateT this_state;
  1892.           long aim;
  1893.  
  1894.           this_state = fragP->fr_subtype;
  1895.           start_type = this_type = md_relax_table + this_state;
  1896.           target = offset;
  1897.  
  1898.           if (symbolP)
  1899.             {
  1900. #ifndef DIFF_EXPR_OK
  1901. #if !defined (MANY_SEGMENTS) && !defined (BFD_ASSEMBLER)
  1902.               know ((S_GET_SEGMENT (symbolP) == SEG_ABSOLUTE)
  1903.                 || (S_GET_SEGMENT (symbolP) == SEG_DATA)
  1904.                 || (S_GET_SEGMENT (symbolP) == SEG_BSS)
  1905.                 || (S_GET_SEGMENT (symbolP) == SEG_TEXT));
  1906. #endif
  1907.               know (symbolP->sy_frag);
  1908. #endif
  1909.               know (!(S_GET_SEGMENT (symbolP) == absolute_section)
  1910.                 || symbolP->sy_frag == &zero_address_frag);
  1911.               target +=
  1912.             S_GET_VALUE (symbolP)
  1913.             + symbolP->sy_frag->fr_address;
  1914.  
  1915.               /* If frag has yet to be reached on this pass,
  1916.              assume it will move by STRETCH just as we did.
  1917.              If this is not so, it will be because some frag
  1918.              between grows, and that will force another pass.
  1919.  
  1920.              Beware zero-length frags.
  1921.  
  1922.              There should be a faster way to do this.  */
  1923.  
  1924.               if (symbolP->sy_frag->fr_address >= was_address
  1925.               && is_dnrange (fragP, symbolP->sy_frag))
  1926.             {
  1927.               target += stretch;
  1928.             }
  1929.             }
  1930.  
  1931.           aim = target - address - fragP->fr_fix;
  1932. #ifdef TC_PCREL_ADJUST
  1933.           /* Currently only the ns32k family needs this */
  1934.           aim += TC_PCREL_ADJUST(fragP);
  1935. #else
  1936.           /* This machine doesn't want to use pcrel_adjust.
  1937.              In that case, pcrel_adjust should be zero.  */
  1938.           assert (fragP->fr_pcrel_adjust == 0);
  1939. #endif
  1940.  
  1941.           if (aim < 0)
  1942.             {
  1943.               /* Look backwards. */
  1944.               for (next_state = this_type->rlx_more; next_state;)
  1945.             if (aim >= this_type->rlx_backward)
  1946.               next_state = 0;
  1947.             else
  1948.               {
  1949.                 /* Grow to next state. */
  1950.                 this_state = next_state;
  1951.                 this_type = md_relax_table + this_state;
  1952.                 next_state = this_type->rlx_more;
  1953.               }
  1954.             }
  1955.           else
  1956.             {
  1957. #ifdef M68K_AIM_KLUDGE
  1958.               M68K_AIM_KLUDGE (aim, this_state, this_type);
  1959. #endif
  1960.               /* Look forwards. */
  1961.               for (next_state = this_type->rlx_more; next_state;)
  1962.             if (aim <= this_type->rlx_forward)
  1963.               next_state = 0;
  1964.             else
  1965.               {
  1966.                 /* Grow to next state. */
  1967.                 this_state = next_state;
  1968.                 this_type = md_relax_table + this_state;
  1969.                 next_state = this_type->rlx_more;
  1970.               }
  1971.             }
  1972.  
  1973.           growth = this_type->rlx_length - start_type->rlx_length;
  1974.           if (growth != 0)
  1975.             fragP->fr_subtype = this_state;
  1976.         }
  1977. #endif
  1978.         break;
  1979.  
  1980.           default:
  1981.         BAD_CASE (fragP->fr_type);
  1982.         break;
  1983.           }
  1984.         if (growth)
  1985.           {
  1986.         stretch += growth;
  1987.         stretched++;
  1988.           }
  1989.       }            /* For each frag in the segment. */
  1990.       }
  1991.     while (stretched);        /* Until nothing further to relax. */
  1992.   }                /* do_relax */
  1993.  
  1994.   /*
  1995.    * We now have valid fr_address'es for each frag.
  1996.    */
  1997.  
  1998.   /*
  1999.    * All fr_address's are correct, relative to their own segment.
  2000.    * We have made all the fixS we will ever make.
  2001.    */
  2002. }                /* relax_segment() */
  2003.  
  2004. #if defined (BFD_ASSEMBLER) || !defined (BFD)
  2005.  
  2006. #ifndef TC_RELOC_RTSYM_LOC_FIXUP
  2007. #define TC_RELOC_RTSYM_LOC_FIXUP(X) (1)
  2008. #endif
  2009.  
  2010. /* fixup_segment()
  2011.  
  2012.    Go through all the fixS's in a segment and see which ones can be
  2013.    handled now.  (These consist of fixS where we have since discovered
  2014.    the value of a symbol, or the address of the frag involved.)
  2015.    For each one, call md_apply_fix to put the fix into the frag data.
  2016.  
  2017.    Result is a count of how many relocation structs will be needed to
  2018.    handle the remaining fixS's that we couldn't completely handle here.
  2019.    These will be output later by emit_relocations().  */
  2020.  
  2021. static long
  2022. fixup_segment (fixP, this_segment_type)
  2023.      register fixS *fixP;
  2024.      segT this_segment_type;    /* N_TYPE bits for segment. */
  2025. {
  2026.   long seg_reloc_count = 0;
  2027.   symbolS *add_symbolP;
  2028.   symbolS *sub_symbolP;
  2029.   valueT add_number;
  2030.   int size;
  2031.   char *place;
  2032.   long where;
  2033.   int pcrel, plt;
  2034.   fragS *fragP;
  2035.   segT add_symbol_segment = absolute_section;
  2036.   
  2037.   /* If the linker is doing the relaxing, we must not do any fixups.
  2038.  
  2039.      Well, strictly speaking that's not true -- we could do any that are
  2040.      PC-relative and don't cross regions that could change size.  And for the
  2041.      i960 (the only machine for which we've got a relaxing linker right now),
  2042.      we might be able to turn callx/callj into bal anyways in cases where we
  2043.      know the maximum displacement.  */
  2044.   if (linkrelax)
  2045.     {
  2046.       for (; fixP; fixP = fixP->fx_next)
  2047.     seg_reloc_count++;
  2048.       TC_ADJUST_RELOC_COUNT (fixP, seg_reloc_count);
  2049.       return seg_reloc_count;
  2050.     }
  2051.  
  2052.   for (; fixP; fixP = fixP->fx_next)
  2053.     {
  2054. #ifdef DEBUG5
  2055.       fprintf (stderr, "\nprocessing fixup:\n");
  2056.       print_fixup (fixP);
  2057. #endif
  2058.  
  2059.       fragP = fixP->fx_frag;
  2060.       know (fragP);
  2061.       where = fixP->fx_where;
  2062.       place = fragP->fr_literal + where;
  2063.       size = fixP->fx_size;
  2064.       add_symbolP = fixP->fx_addsy;
  2065. #ifdef TC_VALIDATE_FIX
  2066.       TC_VALIDATE_FIX (fixP, this_segment_type, skip);
  2067. #endif
  2068.       sub_symbolP = fixP->fx_subsy;
  2069.       add_number = fixP->fx_offset;
  2070.       pcrel = fixP->fx_pcrel;
  2071.       plt = fixP->fx_plt;
  2072.  
  2073.       if (add_symbolP)
  2074.     add_symbol_segment = S_GET_SEGMENT (add_symbolP);
  2075.       
  2076.       if (sub_symbolP)
  2077.     {
  2078.       if (!add_symbolP)
  2079.         {
  2080.           /* Its just -sym */
  2081.           if (S_GET_SEGMENT (sub_symbolP) == absolute_section)
  2082.         add_number -= S_GET_VALUE (sub_symbolP);
  2083.           else if (pcrel
  2084.                && S_GET_SEGMENT (sub_symbolP) == this_segment_type)
  2085.         {
  2086.           /* Should try converting to a constant.  */
  2087.           goto bad_sub_reloc;
  2088.         }
  2089.           else
  2090.           bad_sub_reloc:
  2091.         as_bad_where (fixP->fx_file, fixP->fx_line,
  2092.                   "Negative of non-absolute symbol %s",
  2093.                   S_GET_NAME (sub_symbolP));
  2094.         }
  2095.       else if ((S_GET_SEGMENT (sub_symbolP) == add_symbol_segment)
  2096.            && (SEG_NORMAL (add_symbol_segment)
  2097.                || (add_symbol_segment == absolute_section)))
  2098.         {
  2099.           /* Difference of 2 symbols from same segment.
  2100.          Can't make difference of 2 undefineds: 'value' means
  2101.          something different for N_UNDF. */
  2102. #ifdef TC_I960
  2103.           /* Makes no sense to use the difference of 2 arbitrary symbols
  2104.          as the target of a call instruction.  */
  2105.           if (fixP->fx_tcbit)
  2106.         as_bad_where (fixP->fx_file, fixP->fx_line,
  2107.                   "callj to difference of 2 symbols");
  2108. #endif /* TC_I960 */
  2109.           add_number += S_GET_VALUE (add_symbolP) -
  2110.         S_GET_VALUE (sub_symbolP);
  2111.  
  2112.           add_symbolP = NULL;
  2113.  
  2114.           /* Let the target machine make the final determination
  2115.          as to whether or not a relocation will be needed to
  2116.          handle this fixup.  */
  2117.           if (!TC_FORCE_RELOCATION (fixP))
  2118.         {
  2119.           fixP->fx_addsy = NULL;
  2120.         }
  2121.         }
  2122.       else
  2123.         {
  2124.           /* Different segments in subtraction. */
  2125.           know (!(S_IS_EXTERNAL (sub_symbolP)
  2126.               && (S_GET_SEGMENT (sub_symbolP) == absolute_section)));
  2127.  
  2128.           if ((S_GET_SEGMENT (sub_symbolP) == absolute_section))
  2129.         add_number -= S_GET_VALUE (sub_symbolP);
  2130.  
  2131. #ifdef DIFF_EXPR_OK
  2132.           else if (S_GET_SEGMENT (sub_symbolP) == this_segment_type
  2133. #if 0 /* Do this even if it's already described as pc-relative.  For example,
  2134.      on the m68k, an operand of "pc@(foo-.-2)" should address "foo" in a
  2135.      pc-relative mode.  */
  2136.                && pcrel
  2137. #endif
  2138.                )
  2139.         {
  2140.           /* Make it pc-relative.  */
  2141.           add_number += (md_pcrel_from (fixP)
  2142.                  - S_GET_VALUE (sub_symbolP));
  2143.           pcrel = 1;
  2144.           fixP->fx_pcrel = 1;
  2145.           sub_symbolP = 0;
  2146.           fixP->fx_subsy = 0;
  2147.         }
  2148. #endif
  2149. #ifdef BFD_ASSEMBLER
  2150.           else if (fixP->fx_r_type == BFD_RELOC_GPREL32
  2151.                || fixP->fx_r_type == BFD_RELOC_GPREL16)
  2152.         {
  2153.           /* Leave it alone.  */
  2154.         }
  2155. #endif
  2156.           else
  2157.         {
  2158.           char buf[50];
  2159.           sprint_value (buf, fragP->fr_address + where);
  2160.           as_bad_where (fixP->fx_file, fixP->fx_line,
  2161.                 "Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %s.",
  2162.                 segment_name (S_GET_SEGMENT (sub_symbolP)),
  2163.                 S_GET_NAME (sub_symbolP), buf);
  2164.         }
  2165.         }
  2166.     }
  2167.  
  2168.       if (add_symbolP)
  2169.     {
  2170.       if (add_symbol_segment == this_segment_type && pcrel && !plt
  2171.           && TC_RELOC_RTSYM_LOC_FIXUP (fixP->fx_r_type))
  2172.         {
  2173.           /*
  2174.            * This fixup was made when the symbol's segment was
  2175.            * SEG_UNKNOWN, but it is now in the local segment.
  2176.            * So we know how to do the address without relocation.
  2177.            */
  2178. #ifdef TC_I960
  2179.           /* reloc_callj() may replace a 'call' with a 'calls' or a
  2180.          'bal', in which cases it modifies *fixP as appropriate.
  2181.          In the case of a 'calls', no further work is required,
  2182.          and *fixP has been set up to make the rest of the code
  2183.          below a no-op. */
  2184.           reloc_callj (fixP);
  2185. #endif /* TC_I960 */
  2186.  
  2187.           add_number += S_GET_VALUE (add_symbolP);
  2188.           add_number -= md_pcrel_from (fixP);
  2189.           pcrel = 0;    /* Lie. Don't want further pcrel processing. */
  2190.           
  2191.           /* Let the target machine make the final determination
  2192.          as to whether or not a relocation will be needed to
  2193.          handle this fixup.  */
  2194.           if (!TC_FORCE_RELOCATION (fixP))
  2195.         {
  2196.           fixP->fx_pcrel = 0;
  2197.           fixP->fx_addsy = NULL;
  2198.         }
  2199.         }
  2200.       else
  2201.         {
  2202.           if (add_symbol_segment == absolute_section)
  2203.         {
  2204. #ifdef TC_I960
  2205.           /* See comment about reloc_callj() above.  */
  2206.           reloc_callj (fixP);
  2207. #endif /* TC_I960 */
  2208.           add_number += S_GET_VALUE (add_symbolP);
  2209.  
  2210.           /* Let the target machine make the final determination
  2211.              as to whether or not a relocation will be needed to
  2212.              handle this fixup.  */
  2213.           if (!TC_FORCE_RELOCATION (fixP))
  2214.             {
  2215.               fixP->fx_addsy = NULL;
  2216.               add_symbolP = NULL;
  2217.             }
  2218.         }
  2219.           else if (add_symbol_segment == undefined_section
  2220. #ifdef BFD_ASSEMBLER
  2221.                || bfd_is_com_section (add_symbol_segment)
  2222. #endif
  2223.                )
  2224.         {
  2225. #ifdef TC_I960
  2226.           if ((int) fixP->fx_bit_fixP == 13)
  2227.             {
  2228.               /* This is a COBR instruction.  They have only a
  2229.                * 13-bit displacement and are only to be used
  2230.                * for local branches: flag as error, don't generate
  2231.                * relocation.
  2232.                */
  2233.               as_bad_where (fixP->fx_file, fixP->fx_line,
  2234.                     "can't use COBR format with external label");
  2235.               fixP->fx_addsy = NULL;
  2236.               fixP->fx_done = 1;
  2237.               continue;
  2238.             }        /* COBR */
  2239. #endif /* TC_I960 */
  2240.           
  2241. #ifdef OBJ_COFF
  2242. #ifdef TE_I386AIX
  2243.           if (S_IS_COMMON (add_symbolP))
  2244.             add_number += S_GET_VALUE (add_symbolP);
  2245. #endif /* TE_I386AIX */
  2246. #endif /* OBJ_COFF */
  2247.           ++seg_reloc_count;
  2248.         }
  2249.           else
  2250.         {
  2251.           seg_reloc_count++;
  2252. #if !defined (TC_I386) || !(defined (OBJ_ELF) || defined (OBJ_COFF))
  2253.           add_number += S_GET_VALUE (add_symbolP);
  2254. #endif
  2255.         }
  2256.         }
  2257.     }
  2258.  
  2259.       if (pcrel)
  2260.     {
  2261.       add_number -= md_pcrel_from (fixP);
  2262.       if (add_symbolP == 0)
  2263.         {
  2264. #ifndef BFD_ASSEMBLER
  2265.           fixP->fx_addsy = &abs_symbol;
  2266. #else
  2267.           fixP->fx_addsy = section_symbol (absolute_section);
  2268. #endif
  2269.           fixP->fx_addsy->sy_used_in_reloc = 1;
  2270.           ++seg_reloc_count;
  2271.         }
  2272.     }
  2273.  
  2274.       if (!fixP->fx_bit_fixP && size > 0)
  2275.     {
  2276.       valueT mask = 0;
  2277.       if (size < sizeof (mask))
  2278.         {
  2279.           /* set all bits to one */
  2280.           mask--;
  2281.           /* Technically, combining these produces an undefined result
  2282.          if size is sizeof (valueT), though I think these two
  2283.          half-way operations should both be defined.  And the
  2284.          compiler should be able to combine them if it's valid on
  2285.          the host architecture.  */
  2286.           mask <<= size * 4;
  2287.           mask <<= size * 4;
  2288.           if ((add_number & mask) != 0
  2289.           && (add_number & mask) != mask)
  2290.         {
  2291.           char buf[50], buf2[50];
  2292.           sprint_value (buf, fragP->fr_address + where);
  2293.           if (add_number > 1000)
  2294.             sprint_value (buf2, add_number);
  2295.           else
  2296.             sprintf (buf2, "%ld", (long) add_number);
  2297.           as_bad_where (fixP->fx_file, fixP->fx_line,
  2298.                 "Value of %s too large for field of %d bytes at %s",
  2299.                 buf2, size, buf);
  2300.         } /* generic error checking */
  2301.         }
  2302. #ifdef WARN_SIGNED_OVERFLOW_WORD
  2303.       /* Warn if a .word value is too large when treated as a signed
  2304.          number.  We already know it is not too negative.  This is to
  2305.          catch over-large switches generated by gcc on the 68k.  */
  2306.       if (!flag_signed_overflow_ok
  2307.           && size == 2
  2308.           && add_number > 0x7fff)
  2309.         as_bad_where (fixP->fx_file, fixP->fx_line,
  2310.               "Signed .word overflow; switch may be too large; %ld at 0x%lx",
  2311.               (long) add_number,
  2312.               (unsigned long) (fragP->fr_address + where));
  2313. #endif
  2314.     }            /* not a bit fix */
  2315.  
  2316.       if (!fixP->fx_done)
  2317.     {
  2318. #ifdef BFD_ASSEMBLER
  2319.       md_apply_fix (fixP, &add_number);
  2320. #else
  2321.       md_apply_fix (fixP, add_number);
  2322. #endif
  2323.  
  2324. #ifndef TC_HANDLES_FX_DONE
  2325.       /* If the tc-* files haven't been converted, assume it's handling
  2326.          it the old way, where a null fx_addsy means that the fix has
  2327.          been applied completely, and no further work is needed.  */
  2328.       if (fixP->fx_addsy == 0 && fixP->fx_pcrel == 0)
  2329.         fixP->fx_done = 1;
  2330. #endif
  2331.     }
  2332. #ifdef TC_VALIDATE_FIX
  2333.     skip: ;
  2334. #endif
  2335. #ifdef DEBUG5
  2336.       fprintf (stderr, "result:\n");
  2337.       print_fixup (fixP);
  2338. #endif
  2339.     }                /* For each fixS in this segment. */
  2340.  
  2341.   TC_ADJUST_RELOC_COUNT (fixP, seg_reloc_count);
  2342.   return seg_reloc_count;
  2343. }
  2344.  
  2345. #endif /* defined (BFD_ASSEMBLER) || !defined (BFD) */
  2346.  
  2347. void
  2348. number_to_chars_bigendian (buf, val, n)
  2349.      char *buf;
  2350.      valueT val;
  2351.      int n;
  2352. {
  2353.   if (n > sizeof (val)|| n <= 0)
  2354.     abort ();
  2355.   while (n--)
  2356.     {
  2357.       buf[n] = val & 0xff;
  2358.       val >>= 8;
  2359.     }
  2360. }
  2361.  
  2362. void
  2363. number_to_chars_littleendian (buf, val, n)
  2364.      char *buf;
  2365.      valueT val;
  2366.      int n;
  2367. {
  2368.   if (n > sizeof (val) || n <= 0)
  2369.     abort ();
  2370.   while (n--)
  2371.     {
  2372.       *buf++ = val & 0xff;
  2373.       val >>= 8;
  2374.     }
  2375. }
  2376.  
  2377. /* for debugging */
  2378. extern int indent_level;
  2379.  
  2380. void
  2381. print_fixup (fixp)
  2382.      fixS *fixp;
  2383. {
  2384.   indent_level = 1;
  2385.   fprintf (stderr, "fix %lx %s:%d", (long) fixp, fixp->fx_file, fixp->fx_line);
  2386.   if (fixp->fx_pcrel)
  2387.     fprintf (stderr, " pcrel");
  2388.   if (fixp->fx_pcrel_adjust)
  2389.     fprintf (stderr, " pcrel_adjust=%d", fixp->fx_pcrel_adjust);
  2390.   if (fixp->fx_im_disp)
  2391.     {
  2392. #ifdef TC_NS32K
  2393.       fprintf (stderr, " im_disp=%d", fixp->fx_im_disp);
  2394. #else
  2395.       fprintf (stderr, " im_disp");
  2396. #endif
  2397.     }
  2398.   if (fixp->fx_tcbit)
  2399.     fprintf (stderr, " tcbit");
  2400.   if (fixp->fx_done)
  2401.     fprintf (stderr, " done");
  2402.   fprintf (stderr, "\n    size=%d frag=%lx where=%ld offset=%lx addnumber=%lx",
  2403.        fixp->fx_size, (long) fixp->fx_frag, (long) fixp->fx_where,
  2404.        (long) fixp->fx_offset, (long) fixp->fx_addnumber);
  2405. #ifdef BFD_ASSEMBLER
  2406.   fprintf (stderr, "\n    %s (%d)", bfd_get_reloc_code_name (fixp->fx_r_type),
  2407.        fixp->fx_r_type);
  2408. #else
  2409. #ifdef NEED_FX_R_TYPE
  2410.   fprintf (stderr, " r_type=%d", fixp->fx_r_type);
  2411. #endif
  2412. #endif
  2413.   if (fixp->fx_addsy)
  2414.     {
  2415.       fprintf (stderr, "\n   +<");
  2416.       print_symbol_value_1 (stderr, fixp->fx_addsy);
  2417.       fprintf (stderr, ">");
  2418.     }
  2419.   if (fixp->fx_subsy)
  2420.     {
  2421.       fprintf (stderr, "\n   -<");
  2422.       print_symbol_value_1 (stderr, fixp->fx_subsy);
  2423.       fprintf (stderr, ">");
  2424.     }
  2425.   fprintf (stderr, "\n");
  2426. }
  2427.  
  2428. /* end of write.c */
  2429.